﻿#Region "Copyright (C) 2005-2011 Team MediaPortal"

' Copyright (C) 2005-2011 Team MediaPortal
' http://www.team-mediaportal.com
' 
' MediaPortal is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 2 of the License, or
' (at your option) any later version.
' 
' MediaPortal is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.

#End Region

Imports System
Imports System.Collections.Generic
Imports Gentle.Framework


Namespace TvDatabase
    ''' <summary>
    ''' Instances of this class represent the properties and methods of a row in the table <b>TvMovieSeriesMapping</b>.
    ''' </summary>
    <TableName("TvMovieSeriesMapping")> _
    Public Class TvMovieSeriesMapping
        Inherits Persistent
#Region "Members"

        Private m_isChanged As Boolean

        <TableColumn("idSeries", NotNull:=True), PrimaryKey(AutoGenerated:=False)> _
        Private m_idSeries As Integer

        <TableColumn("disabled", NotNull:=True)> _
      Private m_disabled As Boolean

        <TableColumn("TvSeriesTitle", NotNull:=True)> _
        Private m_TvSeriesTitle As String

        <TableColumn("EpgTitle", NotNull:=True)> _
        Private m_EpgTitle As String

        <TableColumn("minSeasonNum", NotNull:=True)> _
           Private m_minSeasonNum As Integer

#End Region

#Region "Constructors"

        ''' <summary> 
        ''' Create an object from an existing row of data. This will be used by Gentle to 
        ''' construct objects from retrieved rows. 
        ''' </summary> 
        Public Sub New(ByVal idSeries As Integer)
            Me.m_idSeries = idSeries
        End Sub

#End Region

#Region "Public Properties"

        ''' <summary>
        ''' Indicates whether the entity is changed and requires saving or not.
        ''' </summary>
        Public ReadOnly Property IsChanged() As Boolean
            Get
                Return m_isChanged
            End Get
        End Property

        ''' <summary>
        ''' Property relating to database column idSeries
        ''' </summary>
        Public Property idSeries() As Integer
            Get
                Return m_idSeries
            End Get
            Set(ByVal value As Integer)
                m_isChanged = m_isChanged Or m_idSeries <> value
                m_idSeries = value
            End Set
        End Property

        Public Property disabled() As Boolean
            Get
                Return m_disabled
            End Get
            Set(ByVal value As Boolean)
                m_isChanged = m_isChanged Or m_disabled <> value
                m_disabled = value
            End Set
        End Property

        Public Property TvSeriesTitle() As String
            Get
                Return m_TvSeriesTitle
            End Get
            Set(ByVal value As String)
                m_isChanged = m_isChanged Or m_TvSeriesTitle <> value
                m_TvSeriesTitle = value
            End Set
        End Property

        Public Property EpgTitle() As String
            Get
                Return m_EpgTitle
            End Get
            Set(ByVal value As String)
                m_isChanged = m_isChanged Or m_EpgTitle <> value
                m_EpgTitle = value
            End Set
        End Property

        Public Property minSeasonNum() As String
            Get
                Return m_minSeasonNum
            End Get
            Set(ByVal value As String)
                m_isChanged = m_isChanged Or m_minSeasonNum <> value
                m_minSeasonNum = value
            End Set
        End Property

#End Region

#Region "Storage and Retrieval"

        ''' <summary>
        ''' Static method to retrieve all instances that are stored in the database in one call
        ''' </summary>
        Public Shared Function ListAll() As IList(Of TvMovieSeriesMapping)
            Return Gentle.Framework.Broker.RetrieveList(Of TvMovieSeriesMapping)()
        End Function

        ''' <summary>
        ''' Retrieves an entity given it's id.
        ''' </summary>
        Public Overloads Shared Function Retrieve(ByVal idSeries As Integer) As TvMovieSeriesMapping
            Dim key As New Key(GetType(TvMovieSeriesMapping), True, "idSeries", idSeries)
            Return Gentle.Framework.Broker.RetrieveInstance(Of TvMovieSeriesMapping)(key)
        End Function

        ''' <summary>
        ''' Retrieves an entity given it's id, using Gentle.Framework.Key class.
        ''' This allows retrieval based on multi-column keys.
        ''' </summary>
        Public Overloads Shared Function Retrieve(ByVal key As Key) As TvMovieSeriesMapping
            Return Gentle.Framework.Broker.RetrieveInstance(Of TvMovieSeriesMapping)(key)
        End Function

        ''' <summary>
        ''' Persists the entity if it was never persisted or was changed.
        ''' </summary>
        Public Overrides Sub Persist()
            If IsChanged OrElse Not IsPersisted Then
                Try
                    MyBase.Persist()
                Catch ex As Exception
                    MyLog.Error("Exception in TvMovieSeriesMapping.Persist() with Message {0}", ex.Message)
                    Return
                End Try
                m_isChanged = False
            End If
        End Sub

#End Region

#Region "Relations"

        ''' <summary>
        ''' alle TvMovieProgram laden (Episoden im EPG)
        ''' </summary>
        <CLSCompliant(False)> _
        Public Function ReferencedTvMovieProgramList() As IList(Of TVMovieProgram)
            Dim key As New Key(GetType(TVMovieProgram), True, "idSeries", idSeries)
            Return Gentle.Framework.Broker.RetrieveList(Of TVMovieProgram)(key)
        End Function

#End Region

        Public Sub Delete()
            Dim list As IList(Of TvMovieSeriesMapping) = ListAll()
            For Each map As TvMovieSeriesMapping In list
                map.Remove()
            Next
            'Remove()
        End Sub
    End Class
End Namespace
